<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 渠道接口
 */
class Channel extends Api
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 渠道更新接口
     * @ApiMethod   (POST)
     * @param string $channel_code  渠道号
     * @param string $ver           版本
     * @param string $sign          sign
     */
    public function update()
    {
        $post         = request()->post();
        $channel_code = !empty($post['channel_code']) ? $post['channel_code'] : '';
        $ver = !empty($post['ver']) ? $post['ver'] : '';
        
        if (empty($channel_code) || empty($ver)) {
            $this->error('渠道号或版本不能为空');
        }
        $result = Db::name('channel')->field('channel_code, channel_name, down_url, is_force')->where('channel_code', $channel_code)->where('ver', $ver)->find();

        if (empty($result)) {
            $this->error('数据不存在');
        }
        $this->success('success', $result);
    }
}
